# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QPainter, QColor, QMouseEvent


class Demo(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('PyQt5事件处理 - 鼠标事件')
        self.setGeometry(300, 300, 400, 200)

        self.label = QLabel(self)
        self.label.move(10, 10)
        self.label.setText('鼠标未点击')

        self.show()

    def mousePressEvent(self, event: QMouseEvent) -> None:
        self.label.setText(f"鼠标点击：x={event.x()}, y={event.y()}")

    def mouseReleaseEvent(self, event: QMouseEvent) -> None:
        self.label.setText(f"鼠标释放：x={event.x()}, y={event.y()}")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Demo()
    sys.exit(app.exec_())